package cn.com.Kol.initiative.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.springblade.core.plugins.dao.Md;
import org.springblade.core.support.ApiResult;
import org.springblade.core.support.BladePage;
import org.springblade.core.support.CMap;
import org.springblade.core.base.controller.BladeController;
import cn.com.Kol.initiative.model.Area;
import cn.com.Kol.initiative.service.AreaService;
import java.util.Map;

/**
 * Generated by Kol.
 * 2019/03/06
 */
@RestController
@RequestMapping("/initiative/area")
public class AreaController extends BladeController {
	private static String LIST_SOURCE = "area.list";
	
	@Autowired
	AreaService service;

	@GetMapping("list")
    public ApiResult list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        BladePage<Map> list = Md.paginate(LIST_SOURCE, Map.class, CMap.init(), page, pageSize);
        return data(list);
    }

	@PostMapping("save")
	public ApiResult save(Area area) {
		boolean temp = service.save(area);
		if (temp) {
			return success("新增成功");
		} else {
			return error("新增失败");
		}
	}

	@PostMapping("update")
	public ApiResult update(Area area) {
		boolean temp = service.update(area);
		if (temp) {
			return success("修改成功");
		} else {
			return error("修改失败");
		}
	}

	@PostMapping("remove")
	public ApiResult remove(@RequestParam String ids) {
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			return success("删除成功");
		} else {
			return error("删除失败");
		}
	}
}
